from pages.base_page import BasePage


class ReleasePage(BasePage):
    shoes_calendar = '//*[@resource-id="cool.dingstock.mobile:id/title_container"]/android.widget.FrameLayout[2]'
    shoes_guide = '//*[@resource-id="cool.dingstock.mobile:id/title_container"]/android.widget.FrameLayout[3]'
    tidal_list = '//*[@resource-id="cool.dingstock.mobile:id/title_container"]/android.widget.FrameLayout[4]'
    recommend = '//*[@resource-id="cool.dingstock.mobile:id/title_container"]/android.widget.FrameLayout[1]'
    all_button = '//*[@resource-id="cool.dingstock.mobile:id/iv_set"]'
    title = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_title_tv"]'
    back = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    first_release_shoe = '//*[@resource-id="cool.dingstock.mobile:id/rv_main_content"]/android.view.ViewGroup[1]/androidx.recyclerview.widget.RecyclerView[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]'
    shoe_name = '//*[@text="Air Jordan 1 Low 北卡蓝 生胶"]'
    shoe_detail_name = '//*[@resource-id="cool.dingstock.mobile:id/home_product_detail_product_name_txt"]'
    release_detail_back = '//*[@resource-id="cool.dingstock.mobile:id/home_product_detail_back_icon"]'
    hot_sale_detail = '//*[@resource-id="cool.dingstock.mobile:id/rv_main_content"]/android.view.ViewGroup[2]/androidx.recyclerview.widget.RecyclerView[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]'
    release_comment_num = '//*[@resource-id="cool.dingstock.mobile:id/home_product_detail_comment_txt"]'
    release_comment_input = '//*[@resource-id="cool.dingstock.mobile:id/circle_dynamic_detail_et"]'
    release_comment_send = '//*[@resource-id="cool.dingstock.mobile:id/send_btn"]'
    first_comment_content = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_content_txt"]'
    release_like_num = '//*[@resource-id="cool.dingstock.mobile:id/home_product_detail_like_txt"]'
    release_dislike_num = '//*[@resource-id="cool.dingstock.mobile:id/home_product_detail_dislike_txt"]'
    market_price = '//*[@resource-id="cool.dingstock.mobile:id/onekey_search_price_layer"]/android.widget.LinearLayout[1]/androidx.appcompat.widget.LinearLayoutCompat[2]'
    check_price_title = '//*[@text="价格查询"]'

    def click_shoes_calendar(self):
        """点击球鞋日历"""
        self.click_xpath(self.shoes_calendar)

    def click_all_and_back(self):
        """点击ALL按钮后获取title文本并返回"""
        self.click_xpath(self.all_button)
        title = self.get_xpath_text(self.title)
        self.click_xpath(self.back)
        return title

    def get_first_release_name(self):
        """获取第一个发售球鞋名称"""
        return self.get_xpath_text(self.shoe_name)

    def get_detail_shoe_name(self):
        """详情页获取名称后返回"""
        self.click_xpath(self.shoe_name)
        result = self.get_xpath_text(self.shoe_detail_name)
        self.click_xpath(self.release_detail_back)
        return result

    def switch_shoes_guide(self):
        """切换到球鞋图鉴"""
        self.swipe_position((0.91, 0.07), (0.128, 0.072))
        self.click_xpath(self.shoes_guide)

    def switch_tidal_list(self):
        """切换都潮牌清单"""
        self.swipe_position((0.91, 0.07), (0.128, 0.072))
        self.click_xpath(self.tidal_list)

    def into_first_release_detail(self):
        """进入第一热门发售详情页"""
        self.click_xpath(self.hot_sale_detail)

    def get_release_comment_num(self):
        """获取第一个热门发售的评论数量"""
        return self.get_xpath_text(self.release_comment_num)

    def publish_comment(self, text):
        """发售一级评论"""
        self.click_xpath(self.release_comment_num)
        self.set_xpath_text(self.release_comment_input, text)
        self.click_xpath(self.release_comment_send)

    def first_release_comment_content(self):
        """获取第一条发售信息评论文本内容 """
        return self.get_xpath_text(self.first_comment_content)

    def get_release_like_num(self):
        """获取热门发售点赞数量"""
        return self.get_xpath_text(self.release_like_num)

    def like_release(self):
        """点赞热门发售"""
        self.click_xpath(self.release_like_num)

    def get_release_dislike_num(self):
        """获取热门发售点踩数量"""
        return self.get_xpath_text(self.release_dislike_num)

    def dislike_release(self):
        """点踩热门发售"""
        self.click_xpath(self.release_dislike_num)

    def check_market_price(self):
        """查询发售球鞋市场价"""
        self.click_xpath(self.market_price)

    def is_check_price_title_exists(self):
        """查询市场价title是否存在"""
        return self.is_xpath_exist(self.check_price_title)
